local fenyin = fk.CreateSkill{
  name = "wk_heg__fenyin",
}


Fk:loadTranslationTable{
  ["wk_heg__fenyin"] = "奋音",
  [":wk_heg__fenyin"] = "出牌阶段开始时，你可以令所有与你势力相同的角色依次选择是否弃置一张牌，若如此做，你于此阶段使用的前X张牌无距离与次数限制且使用时摸一张牌（X为以此法弃牌数）。",
  
  ["wk_heg__fenyin_ask"] = "奋音：你可以弃置一张牌，令 留赞 使用牌无距离与次数限制",
  ["#wk_heg__fenyin_effect"] = "奋音",
  ["#wk_heg__weifu_targetmod"] = "奋音",
  ["@wk_heg__fenyin-phase"] = "奋音",
}

local H = require "packages.ol_hegemony.util"

fenyin:addEffect(fk.EventPhaseStart, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(fenyin.name) and player == target and player.phase == Player.Play
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local count = 0
    local targets = table.filter(room.alive_players, function (p) return H.compareKingdomWith(p, player) end)
    room:sortByAction(targets)
    for _, p in ipairs(targets) do
      if not p.dead then
        if #room:askToDiscard(p, {
            min_num = 1,
            max_num = 1,
            include_equip = true,
            skill_name = fenyin.name,
            prompt = "wk_heg__fenyin_ask",
            cancelable = true,
          }) > 0 then
          count = count + 1
        end
      end
    end
    room:setPlayerMark(player, "@wk_heg__fenyin-phase", count)
  end,
})

fenyin:addEffect(fk.CardUsing, {
  is_delay_effect = true,
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return player:getMark("@wk_heg__fenyin-phase") > 0 and player == target and player.phase == Player.Play and data.card
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player:drawCards(1, fenyin.name)
    player.room:addPlayerMark(player, "@wk_heg__fenyin-phase", -1)
  end,
})

fenyin:addEffect("targetmod", {
  is_delay_effect = true,
  bypass_times = function(self, player, skill, scope, card, to)
    return card and player:getMark("@wk_heg__fenyin-phase") > 0
  end,
  bypass_distances =  function(self, player, skill, card, to)
    return card and player:getMark("@wk_heg__fenyin-phase") > 0
  end,
})

return fenyin
